<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2017 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: Dean <zxxjjforever@163.com>
// +----------------------------------------------------------------------
namespace api\user\controller;

use cmf\controller\RestUserBaseController;
use think\Db;
use think\Validate;
use api\user\model\SchoolModel as School;

class UserController extends RestUserBaseController
{

	/**
	 * [getSchoolList 获取学校列表]
	 * @param  School $School [学校表模型类]
	 * @param  name [学校名字like查询]
	 * @return 
	 */
   public function getSchoolList(School $School){
   		$name = $this->request->param('name');
   		if($name){
   			$where['name'] = ['like',"%$name%"];
   			$data = $School->getList($where);
   		}else{
   			$data = array();
   		}
   		$this->success('',$data);

   }


  //语音识别转换文字
   public function aip(){
      Vendor('aip.AipSpeech');
      $this->APP_ID = '15489000';
      $this->API_KEY = '2fvHkSMxbIXSGr4BjupHB3M1';
      $this->SECRET_KEY = 'iYYt8n6MSuS5Vu2GClMrFUSmmoXm4TzS';

      $url = $this->request->post('file');
       $path = $this->request->post('path');
      if(empty($url)){
         $this->error('缺失参数');die;
      }
      $client = new \AipSpeech($this->APP_ID, $this->API_KEY, $this->SECRET_KEY);

     
      $re = $client->asr(file_get_contents($url), 'pcm', 16000, array(
          'dev_pid' => 1536,
      ));

      unlink(ROOT_PATH . 'public' . DS . 'upload/sound/'.$path);
     
      if($re['err_no'] == 0){
         $this->success('成功',$re);
      }else{
         $this->error('失败',$re);
      }

   }


   //反馈提交
   public function feedbackPost(){
      $userId = $this->getUserId();
      $data = $this->request->post();
      $data['userId'] = $userId;
      $data['createTime'] = date('Y-m-d H:i:s',time());
      if(!empty($data['imgs'])){
         $data['imgs'] = implode(',', $data['imgs']);
      }
      $re = Db::name('feedback')->insert($data);
      if($re){
         $this->success('反馈成功!');
      }else{
         $this->error('请求错误');
      }
     

   }

}
